package com.mtsmda.jpa.eclipseLink.vogella.domain.oneToMany;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "FAMILIES")
public class Family {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID_FAMILY")
	private Integer idFamily;

	@Column(name = "DESCRIPTION_FAMILY", length = 50)
	private String description;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "family", targetEntity = PersonFamily.class)
	private List<PersonFamily> personFamilies = new ArrayList<>();

	public Family() {
		super();
	}

	public Family(String description) {
		this();
		setDescription(description);
	}

	public Integer getIdFamily() {
		return idFamily;
	}

	public void setIdFamily(Integer idFamily) {
		this.idFamily = idFamily;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<PersonFamily> getPersonFamilies() {
		return personFamilies;
	}

	public void setPersonFamilies(List<PersonFamily> personFamilies) {
		this.personFamilies = personFamilies;
	}

	@Override
	public String toString() {
		return "Family [idFamily=" + idFamily + ", description=" + description
				+ ", personFamilies=" + personFamilies + "]";
	}

}